<template>
  <view class="content">
    <view class="searchBox">
      <u-calendar :show="show" mode="range" @confirm="confirm" @close="show = false" :allowSameDay="true"
        :minDate="minDate" :closeOnClickOverlay="true" monthNum="13"></u-calendar>
      <view class="timeBox" @click="show = true">
        <span style="margin-right: 10rpx;">日期</span>
        <view class="time">
          <image src="../../static/img/time.png" mode=""></image>
          {{info.start_date}}
        </view>
        <view style="margin: 0 10rpx;">
          至
        </view>
        <view class="time">
          <image src="../../static/img/time.png" mode=""></image>
          {{info.end_date}}
        </view>
      </view>
      <view class="iptBox">
        <input class="ipt" type="text" placeholder="输入关键词" placeholder-class="iptPla" v-model="info.search_data">
        <view class="searchBtn" @tap="getTeacherPlanList()">
          搜索
        </view>
      </view>
    </view>

    <view class="list">
      <view class="item" v-for="(i,k) in list" :key="k" @tap="goDetail(i.teacher_id)">
        <view class="row flex">
          <view class="">
            <image class="img" src="../../static/img/account.png" mode=""></image>
            {{i.teacher_nickname}}
            <text style="margin-left: 10rpx;">({{i.teacher_phone}})</text>
          </view>
          <view class="">
            <image class="img" src="../../static/img/aicient.png" mode=""></image>
            <text style="margin-left: 10rpx;">({{i.school_name}})</text>
          </view>
        </view>

        <view class="row flex">
          <view class="">
            <image class="alarm" src="../../static/img/alarm.png" mode=""></image>
            {{i.all_hour}}小时
            <text style="margin-left: 10rpx;">(总课时)</text>
          </view>
          <view class="">
            <image class="alarm" src="../../static/img/alarm.png" mode=""></image>
            {{i.stage_hour}}小时
            <text style="margin-left: 10rpx;color: #4E88E6;">(阶段课时)</text>
          </view>
        </view>
        <view class="btm flex">
          <view style="color: #FF8D1A;">
            {{i.all_hour}}小时
            <text style="margin-left: 10rpx;">(体验课时)</text>
          </view>
          <view style="color: #000;">
            {{i.all_hour}}小时
            <text style="margin-left: 10rpx;">(正式课时)</text>
          </view>
          <view style="color: #AC33C1;">
            {{i.all_hour}}小时
            <text style="margin-left: 10rpx;">(复习课时)</text>
          </view>
        </view>
        <u-icon class="icon" name="arrow-right"></u-icon>
      </view>
    </view>

  </view>
</template>

<script>
  export default {
    data() {
      return {
        show: false,
        info: {
          start_date: '',
          end_date: '',
          search_data: ''
        },
        value1: '',
        maxDate: '',
        minDate: '',
        list: [],
      }
    },
    onLoad() {
      this.chooseTimed()
      this.getDate()
      this.getTeacherPlanList()
    },
    methods: {
      // 设置默认日期，最大值为今天，最小值为去年今天
      chooseTimed() {
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        if (month <= 9) {
          month = '0' + month;
        }
        if (day <= 9) {
          day = '0' + day;
        }
        let minyear = year - 1;
        this.minDate = minyear + '-' + month + '-' + day;
        this.maxDate = year + '-' + month + '-' + day;
      },
      getDate() {
        const currentDate = new Date();
        const year = currentDate.getFullYear();
        const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份是从0开始的
        const day = currentDate.getDate().toString().padStart(2, '0');
        const formattedDate = `${year}-${month}-${day}`;
        this.info.start_date = formattedDate
        this.info.end_date = formattedDate
      },
      confirm(e) {
        this.info.start_date = e[0].replace(/-/g, "-");
        this.info.end_date = e[e.length - 1].replace(/-/g, "-");
        this.show = false
      },
      cancel() {
        this.leaveShow = false
        this.feedbackShow = false
        this.demoShow = false
        this.seeShow = false
      },
      async getTeacherPlanList() {
        const {
          data: res
        } = await uni.$http.post('school/teacher/getTeacherPlanList', this.info)
        if (res.code != 1) {
          return this.toast.msg(res.msg)
        }
        this.list = res.data
      },
      goDetail(teacher_id) {
        uni.navigateTo({
          url: `/pages/coach/timeDetail?teacher_id=${teacher_id}`
        })
      }
    }
  }
</script>

<style lang="scss">
  .content {
    .star {
      color: #D43030;
      margin-left: 11rpx;
    }

    .btns {
      color: #FFFFFF;
      text-align: center;
      line-height: 36rpx;
      font-size: 21rpx;
      margin-left: 293rpx;
      display: flex;

      view {
        width: 80rpx;
        height: 36rpx;
        border-radius: 8rpx;
      }

      .cancel {
        background: #A6A6A6;
        margin-right: 32rpx;
      }

      .confirm {
        background-color: #2A82E4;
      }
    }

    .searchBox {
      width: 670rpx;
      margin: 0 auto;
      padding: 0 20rpx;

      .timeBox {
        display: flex;
        height: 78rpx;
        line-height: 78rpx;
        align-items: center;
        margin-bottom: 18rpx;
        font-size: 21rpx;

        .time {
          width: 250rpx;
          height: 78rpx;
          border-radius: 10rpx;
          background: #FFFFFF;
          border: 2rpx solid #FCF7F7;
          padding-left: 26rpx;
          color: #666;

          image {
            width: 35rpx;
            height: 35rpx;
            margin-right: 17rpx;
            vertical-align: middle;
          }
        }
      }

      .iptBox {
        display: flex;

        .ipt {
          box-sizing: border-box;
          width: 520rpx;
          height: 66rpx;
          padding-left: 75rpx;
          border: 2rpx solid #FCF7F7;
          border-radius: 10rpx;
        }

        .iptPla {
          color: #999;
          font-size: 22rpx;
        }

        .searchBtn {
          display: inline-block;
          background: #A6A6A6;
          width: 100rpx;
          height: 66rpx;
          line-height: 66rpx;
          text-align: center;
          border-radius: 10rpx;
          margin-left: 20rpx;
          font-size: 24rpx;
        }
      }
    }

    .list {
      width: 698rpx;
      margin: 0 auto;
      margin-top: 20rpx;

      .item {
        position: relative;
        margin-bottom: 15rpx;
        width: 698rpx;
        min-height: 168rpx;
        border-radius: 10rpx;
        background: #FFFFFF;
        border: 2rpx solid #ECECEC;
        color: #666;
        font-size: 24rpx;
        padding: 20rpx 30rpx;

        .row {
          width: 100%;
          margin: 10rpx 0;

          >view {
            width: 50%;

            .img {
              width: 28rpx;
              height: 23rpx;
              margin-right: 20rpx;
            }

            .alarm {
              width: 26rpx;
              height: 26rpx;
              margin-right: 20rpx;
            }
          }
        }

        .btm {
          width: 100%;

          view {
            width: 33%;
          }
        }

        .icon {
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
          right: 30rpx;
        }
      }
    }
  }
</style>